@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.index')}}"><h5 class="content-header-title">分类列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.create')}}"> <h5 class="content-header-title">添加分类</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <h5 class="content-header-title">编辑分类</h5>
            </div>

        </div>
        <form action="{{route('classify.classify.update',$classify)}}" method="post">
            @csrf @method('PUT')
            <div class="content-body">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">分类名称</label>
                                    <input type="text" class="form-control" name="name" value="{{$classify->name}}"  aria-describedby="helpId" placeholder="">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">父级分类</label>
                                    <select class="form-control" name="pid" id="classify">
                                        <option pid="0" value="0">顶级分类</option>
                                        @foreach($classifys as $class)
                                            <option {{$classify->pid==$class->id?'selected':''}} pid="{{$class->pid}}" value="{{$class->id}}">{{$class->name}}</option>
                                            @foreach($class->classifySon($class->id) as $value)
                                                <option {{$classify->pid==$value->id?'selected':''}} pid="{{$value->pid}}" value="{{$value->id}}"> 二级:{{$value->name}}</option>
                                                @foreach($value->classifySon($value->id) as $item)
                                                    <option {{$classify->pid==$item->id?'selected':''}} pid="{{$item->pid}}" value="{{$item->id}}"> .....三级:{{$item->name}}</option>
                                                    @endforeach
                                            @endforeach
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        @if($classify->level==3)
                        <div id="attribute"  class="row">
                            <div class="col-6">
                                <label for="" class="mr-2">可用属性</label>
                                @foreach($attributes as $attribute)
                                    <div class="form-check form-check-inline">
                                        <input {{in_array($attribute->id,$attrId)?'checked':''}} name="attribute[]" class="form-check-input"type="checkbox" id="{{$attribute['id']}}" value="{{$attribute['id']}}">
                                        <label class="form-check-label" for="{{$attribute['id']}}">{{$attribute->name}}</label>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                        @endif
                    </div>
                    <div class="card-footer text-muted " >
                        <button type="submit" class="btn btn-primary ">保存数据</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

@endsection
@push('js')
    <script>
        $('#classify').change(function () {
            var value= $(this).find('option:checked').attr('pid');
            if (value==0){
                $('#attribute').hide();
            } else{
                $('#attribute').show();
            }
        })
    </script>
@endpush
